package com.java8.MethodRef;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

/**
 * 数组的构造方法(创建数组)
 * 数据类型[]::new
 */
public class demo_6 {
    //创建一个指定类型的数组
    public static void main(String[] args) {
        //1.创建集合并添加元素
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5);

//        Integer[] arr = list.stream().toArray(new IntFunction<Integer[]>() {
//                @Override
//                public Integer[] apply(int value) {
//                    return new Integer[value];
//                }
//        });
        //方法引用
        Integer[] arr = list.stream().toArray(Integer[]::new);
        System.out.println(Arrays.toString(arr));

        System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
        //1.创建集合并添加元素
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "张无忌,15", "周芷若,14", "赵敏,13", "张强,20", "张三丰,100", "张翠山,40", "张良,35", "王二麻子,37", "谢广坤,41");
        //2.先把字符串变成Student对象，然后再把Student对象收集起来
        Student[] arr1 = list1.stream().map(Student::new).toArray(Student[]::new);
        //打印数组
        System.out.println(Arrays.toString(arr1));
    }
}
